#ifndef _XMLOADER_H
#define _XMLOADER_H

#define SIZE 1024

#include "../StdAfx.h"

#include <libxml/xmlmemory.h> 
#include <libxml/parser.h>

struct modelData
{
    std::vector<GLuint> m_pCordIdList;
    std::vector<GLuint> m_pTextCoordsIdList;
    std::vector<GLuint> m_pColorsIdList;
    std::vector<GLuint> m_pMatIdsList;
    
    std::vector<GLfloat> m_pVertices;
    std::vector<GLfloat> m_pNormals;
    std::vector<GLfloat> m_pColors;
    std::vector<GLfloat> m_pTexCoords;
    
    std::string name;
    std::string layer;
    std::string type;
    int matID;
};

class cXmlLoader {
    
private:
    
    // Metodos privados
    
    int Mcount(char S[SIZE], char c);
    float Matof(std::string s);
    
    void TokenizeXmlValueToInt(std::vector<GLuint>* pList, xmlDocPtr doc, xmlNodePtr cur);
    void TokenizeXmlValueToFloat(std::vector<GLfloat>* pList, xmlDocPtr doc, xmlNodePtr cur);
    int GetCountFromXml(xmlNodePtr cur);
    
    std::string GetPropFromXml(xmlNodePtr cur, const char* name);
    
    void ParseMaterials (xmlDocPtr doc, xmlNodePtr cur);
    void ParseMaterial (xmlDocPtr doc, xmlNodePtr cur);
    void ParseMeshes (xmlDocPtr doc, xmlNodePtr cur);
    void ParseMesh (xmlDocPtr doc, xmlNodePtr cur);
    void ParseXML(char *docname);
    
    void LoadModelData();
    
public:
    
    // Parseo de XML
    std::vector<GLuint> m_pCordIdList;
    std::vector<GLuint> m_pTextCoordsIdList;
    std::vector<GLuint> m_pColorsIdList;
    std::vector<GLuint> m_pMatIdsList;
    
    std::vector<GLfloat> m_pVertices;
    std::vector<GLfloat> m_pNormals;
    std::vector<GLfloat> m_pColors;
    std::vector<GLfloat> m_pTexCoords;
    std::vector<std::string> m_pTexturesNamesList;
    
    std::vector<modelData> m_pModelData;
    
    std::string name;
    std::string layer;
    std::string type;
    int matID;
    
    //std::string UVTiling;
    //std::string UVOffset;
    
    // Metodos publicos
    cXmlLoader(char* filename);

    ~cXmlLoader();
};

#endif // _MODEL_H